/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(
  initialState: { currentUser?: AccountData.CurrentAccountVo } | undefined,
) {
  const { currentUser } = initialState ?? {};

  const permissionsArray = currentUser?.permissions || [];
  const permissionsStr = permissionsArray.toString() || '';
  const admin = permissionsStr.indexOf('admin') !== -1;

  return {
    showAdmin: admin,
    /**
     * ======================================================================================
     * 签到推广
     * ======================================================================================
     */
    showPromotion: permissionsStr.indexOf('promotion') > -1,
    签到推广x创建: permissionsArray.includes('promotion:create'),
    签到推广x更新: permissionsArray.includes('promotion:update'),
    签到推广x列表x管理员: permissionsArray.includes('promotion:page:create'),
    /**
     * ======================================================================================
     * 线索上报
     * ======================================================================================
     */
    showCues: permissionsStr.indexOf('cues') > -1,

    /**
     *  选题计划
     */
    showCuesTopic: permissionsStr.indexOf('cues:topic') > -1,
    线索上报x选题计划x配置x管理员: permissionsArray.includes('cues:topic:config:manage'),
    线索上报x选题计划x配置x需求者: permissionsArray.includes('cues:topic:config:demand'),
    线索上报x选题计划x配置x提供者管理员: permissionsArray.includes(
      'cues:topic:config:renderManage',
    ),
    线索上报x选题计划x配置x提供者: permissionsArray.includes('cues:topic:config:render'),
    线索上报x选题计划x计划列表x列表: permissionsArray.includes('cues:topic:page:page'),
    线索上报x选题计划x计划列表x详情页面: permissionsArray.includes('cues:topic:page:details'),
    线索上报x选题计划x计划列表x创建计划: permissionsArray.includes('cues:topic:page:create'),
    线索上报x选题计划x计划列表x更新计划: permissionsArray.includes('cues:topic:page:update'),
    线索上报x选题计划x选题列表x列表: permissionsArray.includes('cues:topic:submit:page'),
    线索上报x选题计划x选题列表x详情页面: permissionsArray.includes('cues:topic:submit:details'),
    线索上报x选题计划x选题列表x上报线索: permissionsArray.includes('cues:topic:submit:create'),
    线索上报x选题计划x选题列表x更新线索: permissionsArray.includes('cues:topic:submit:update'),
    线索上报x选题计划x选题列表x收录线索: permissionsArray.includes('cues:topic:submit:adopt'),
    线索上报x选题计划x选题列表x评分线索: permissionsArray.includes('cues:topic:submit:score'),
    线索上报x选题计划x计划列表x创建计划x多条选题计划: true,
    // 线索上报x选题计划x计划列表x创建计划x多条选题计划: permissionsArray.includes('cues:topic:page:create:plan:multiple'),
    /**
     *  主动报送
     */
    showCuesActive: permissionsStr.indexOf('cues:active') > -1,
    线索上报x主动报送x配置x管理员: permissionsArray.includes('cues:active:config:manage'),
    线索上报x主动报送x配置x需求者: permissionsArray.includes('cues:active:config:demand'),
    线索上报x主动报送x配置x提供者管理员: permissionsArray.includes(
      'cues:active:config:renderManage',
    ),
    线索上报x主动报送x配置x提供者: permissionsArray.includes('cues:active:config:render'),
    线索上报x主动报送x选题列表x列表: permissionsArray.includes('cues:active:page:page'),
    线索上报x主动报送x选题列表x详情页面: permissionsArray.includes('cues:active:page:details'),
    线索上报x主动报送x选题列表x上报线索: permissionsArray.includes('cues:active:page:create'),
    线索上报x主动报送x选题列表x更新线索: permissionsArray.includes('cues:active:page:update'),
    线索上报x主动报送x选题列表x收录线索: permissionsArray.includes('cues:active:page:adopt'),
    线索上报x主动报送x选题列表x评分线索: permissionsArray.includes('cues:active:page:score'),

    showCuesAdopt:
      (permissionsArray.includes('cues:topic:config:manage') ||
        permissionsArray.includes('cues:topic:config:demand') ||
        permissionsArray.includes('cues:active:config:manage') ||
        permissionsArray.includes('cues:active:config:demand')) &&
      (permissionsArray.includes('cues:topic:submit:adopt') ||
        permissionsArray.includes('cues:active:page:adopt')),

    showCuesScore:
      (permissionsArray.includes('cues:active:config:manage') ||
        permissionsArray.includes('cues:active:config:demand')) &&
      (permissionsArray.includes('cues:topic:submit:score') ||
        permissionsArray.includes('cues:active:page:score')),

    /**
     * ======================================================================================
     * 宣传刊播
     * ======================================================================================
     */
    showPublicity: permissionsStr.indexOf('publicity') > -1,

    宣传刊播x配置x管理员: permissionsArray.includes('publicity:config:manage'),
    宣传刊播x配置x预览者: permissionsArray.includes('publicity:config:preview'),
    宣传刊播x来源: permissionsArray.includes('publicity:source'),
    宣传刊播x创建: permissionsArray.includes('publicity:create'),
    宣传刊播x更新: permissionsArray.includes('publicity:update'),

    /**
     * ======================================================================================
     * 数据分析
     * ======================================================================================
     */
    showAnalysis: permissionsStr.indexOf('analysis:config:manage') > -1,
    数据分析x配置x管理员: permissionsArray.includes('analysis:config:manage'),
    数据分析x配置x预览者: permissionsArray.includes('analysis:config:preview'),
    数据分析x预览模块: permissionsArray.includes('analysis:target'),
    数据分析播x趋势模块: permissionsArray.includes('analysis:trend'),
    数据分析x综合面板: permissionsArray.includes('analysis:overall'),
  };
}
